<?php
include 'init.php';
include "./include/membersite_config.php";

if($fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("index.php");
    exit;
}


if(isset($_POST['submitted']))
{
   if($fgmembersite->RegisterUser())
   {
        $fgmembersite->RedirectToURL("thank-you.html");
   }
}

include 'template/header_for_reg.php';
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
    <title>Contact us</title>
    <link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css" />
    <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
    <link rel="STYLESHEET" type="text/css" href="style/pwdwidget.css" />
    <script src="scripts/pwdwidget.js" type="text/javascript"></script>      
</head>
<body>

<!-- Form Code Start -->
<div id='fg_membersite'>
<form id='register' action="<?php echo $fgmembersite->GetSelfScript(); ?>" method='post' accept-charset='UTF-8'>

<legend>Register</legend></br >

<input type='hidden' name='submitted' id='submitted' value='1'/>

<div class='short_explanation'>* required fields</div></br>
<input type='text'  class='spmhidip' name="<?php echo $fgmembersite->GetSpamTrapInputName(); ?>" />

<div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>
<div class='container'>
    <label id = 'f1' for='email' >Email Address*:</label><br/>
    <input type='text' id = 'reg' name='email' id='email' value="<?php echo $fgmembersite->SafeDisplay('email') ?>" maxlength="80" /><br/>
    <span id='register_email_errorloc' class='error'></span>
</div>

<div class='container'>
    <label id = f1 for='name' >Your Full Name*: </label><br/>
    <input type='text' name='name' id = 'reg' id='name' value="<?php echo $fgmembersite->SafeDisplay('name') ?>" maxlength="50" /><br/>
    <span id='register_name_errorloc' class='error'></span>
</div>

<div class='container'>
    <label id = f1 for='username' >Phone number:</label><br/>
    <input type='text' name='tel' id = 'reg' id='username' value="<?php echo $fgmembersite->SafeDisplay('tel') ?>" maxlength="50" /><br/>
    <span id='register_username_errorloc' class='error'></span>
</div>
<div class='container' style='height:60px;'>
    <label id = f1 for='password' >Password*:</label><br/>
    <div class='pwdwidgetdiv' id='thepwdddiv' ></div><br/>
    <noscript>
    <input type='password' name='password' id='password' maxlength="50" />
    </noscript>    
    <span id='register_password_errorloc' class='error' style='clear:both'></span>
</div>

    <input type='submit' class='button' id='reg' name='Register' value='Register' /> 
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href="index.php">back</a> 



</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->

<script type='text/javascript'>
// <![CDATA[
    var pwdwidget = new PasswordWidget('thepwdddiv','password');
    pwdwidget.MakePWDWidget();
    
    var frmvalidator  = new Validator("register");
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();
    frmvalidator.addValidation("name","req","Please provide your name");

    frmvalidator.addValidation("email","req","Please provide your email address");

    frmvalidator.addValidation("email","email","Please provide a valid email address");

    frmvalidator.addValidation("username","req","Please provide a username");
    
    frmvalidator.addValidation("password","req","Please provide a password");

// ]]>
</script>
<div id='fg_crdiv'><p><a href='http://www.html-form-guide.com'
>HTML form guide - email forms, registration forms, form generators and more</a>.</p></div>
</div>
<!--
Form Code End (see html-form-guide.com for more info.)
-->

</body>
</html>
<!--

if (isset($_POST['register_email'], $_POST['register_name'], $_POST['register_password'])) {
  $register_email = $_POST['register_email'];
  $register_name = $_POST['register_name'];
  $register_password = $_POST['register_password'];
  
  $errors = array();
  
  if (empty($register_email) || empty($register_name) || empty($register_password)) {
    $errors[] = 'All field required';
  } else {
  
    /*if (filter_var($register_email, FILTER_VALIDATE_EMAIL) === false) {
	  $errors[] = 'Email address not valid';
	}*/
	
	if (strlen($register_email) > 255 || strlen($register_name) > 35 || strlen($register_password) > 35) {
	  $errors[] = 'One or more fields contains too many characters';
	}
	
	if (user_exists($register_email) === true) {
	  $errors[] = 'That email has already been registered';
	}
	
	}
	
	if (!empty($errors)) {
	  foreach ($errors as $error) {
	    echo $error, '<br />';
	  }
	} else {
	 $register = user_register($register_email, $register_name, $register_password);
	 $_SESSION['user_id'] = $register;
	 //echo $_SESSION['user_id'];
	 header('Location: index.php');
	 exit();
	}
	
	
}


<form action="" method="post">
	<p>Email:<br /> <input type="email" name="register_email" size="35" maxlength="255" /></p>
	<p>Full name: <br /><input type="text" name="register_name" maxlength="35" /></p>
	<p>Password:<br /> <input type="password" name="register_password" maxlength="35" /></p>
	<p><input type="submit" value="Register" /></p>
</form>


include 'template/footer.php';
-->
